package com.couldtest.providerA.controller;

import com.alibaba.fastjson.JSON;
import com.couldtest.providerA.entity.User;
import com.couldtest.providerA.service.UserService;
import com.netflix.discovery.EurekaClient;
import com.spring4all.swagger.EnableSwagger2Doc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by liguanfu on 2018/6/6.
 */
@EnableSwagger2Doc
@RestController
public class DcController {

    @Autowired
    DiscoveryClient discoveryClient;
    @Resource
    private UserService userService;

    @GetMapping("/dc")
    public String dc() {
        String services = "Services: " + discoveryClient.getServices();
        System.out.println(services);
        return services;
    }


    @GetMapping("/dcx")
    public String dcx(Long id) throws InterruptedException {
        User user = userService.getUser(id);
        String s = JSON.toJSONString(user);
        return "provider-A";
    }


   /* @GetMapping("/dcx1")
    public String dcx1(@RequestParam("id") String id ,@RequestParam("name") String name) {
        return "服务—A,dcx1，姓名："+name+"编号："+id;
    }


    @GetMapping("/dcx2")
    public String dcx2(@RequestHeader("id") String id , @RequestHeader("name") String name) {
        return "服务—A,dcx2，姓名："+name+"编号："+id;
    }*/
}
